package com.cash.loan.modular.user.service;

import com.cash.loan.common.util.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * 清除ip黑名单任务
 * @author yangbo
 * @date 2019-08-27 13:16
 */
@Component
public class SmsIpScheduing {

    private static final Logger log = LoggerFactory.getLogger(SmsIpScheduing.class);

    @Autowired
    private RedisUtil redisUtil;

    /**
     * ip黑名单
     */
    private static final String IP_BLACK_LIST = "ip_black_list:*";

    private static final String PHONE_BLACK_LIST = "phone_black_list:*";

    @Scheduled(cron = "0 0 0 * * ? ")
    public void cleanBlackIpList() {
        Set<String> keys = redisUtil.getKeyByPattern(IP_BLACK_LIST);
        Set<String> phoneKeys = redisUtil.getKeyByPattern(PHONE_BLACK_LIST);
        redisUtil.deleteKeys(keys);
        redisUtil.deleteKeys(phoneKeys);
    }
}
